<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>视频播放 - 视频播放平台</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <link href="https://vjs.zencdn.net/8.3.0/video-js.css" rel="stylesheet">
    <link href="https://unpkg.com/@videojs/themes@1/dist/forest/index.css" rel="stylesheet">
    <style>
        :root {
            --primary-color: #4361ee;    /* 明亮的蓝色 */
            --secondary-color: #3f37c9;  /* 深蓝色 */
            --accent-color: #4895ef;     /* 浅蓝色 */
            --text-color: #2b2d42;       /* 深灰蓝色文字 */
            --light-bg: #f8f9fa;         /* 浅灰背景 */
            --dark-bg: #4361ee;          /* 主色调背景 */
        }

        body {
            background-color: var(--light-bg);
            color: var(--text-color);
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }

        .header {
            background: linear-gradient(135deg, #4361ee, #3f37c9);
            box-shadow: 0 4px 15px rgba(67, 97, 238, 0.2);
            color: white;
            padding: 1rem 0;
            margin-bottom: 2rem;
        }

        .main-container {
            max-width: 1400px;
            margin: 0 auto;
            padding: 0 1rem;
        }

        .video-section {
            display: grid;
            grid-template-columns: 70% 30%;
            gap: 2rem;
            margin-bottom: 2rem;
        }

        .video-player-container {
            background: white;
            border-radius: 16px;
            overflow: hidden;
            box-shadow: 0 4px 20px rgba(67, 97, 238, 0.1);
        }

        .video-info {
            padding: 1.5rem;
        }

        .video-title {
            font-size: 1.5rem;
            font-weight: 600;
            margin-bottom: 1rem;
            color: #2b2d42;
        }

        .video-meta {
            display: flex;
            gap: 1.5rem;
            color: #666;
            margin-bottom: 1.5rem;
        }

        .video-meta span {
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }

        .video-meta i {
            color: #4895ef;
        }

        .video-description {
            background: #f8f9fa;
            padding: 1rem;
            border-radius: 8px;
            color: #666;
            line-height: 1.6;
            border: 1px solid rgba(67, 97, 238, 0.1);
        }

        .related-videos {
            background: white;
            border-radius: 16px;
            padding: 1.5rem;
            box-shadow: 0 4px 20px rgba(67, 97, 238, 0.1);
        }

        .related-videos h3 {
            margin-bottom: 1.5rem;
            font-size: 1.2rem;
            font-weight: 600;
        }

        .related-video-item {
            display: flex;
            gap: 1rem;
            padding: 0.75rem;
            border-radius: 8px;
            cursor: pointer;
            transition: background-color 0.3s ease;
            margin-bottom: 1rem;
        }

        .related-video-item:hover {
            background-color: rgba(67, 97, 238, 0.05);
        }

        .related-video-thumb {
            width: 120px;
            height: 68px;
            object-fit: cover;
            border-radius: 4px;
        }

        .related-video-info {
            flex: 1;
        }

        .related-video-title {
            font-weight: 500;
            margin-bottom: 0.5rem;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
            overflow: hidden;
        }

        .related-video-meta {
            font-size: 0.9rem;
            color: #666;
        }

        @media (max-width: 992px) {
            .video-section {
                grid-template-columns: 1fr;
            }
        }

        .back-button {
            display: inline-flex;
            align-items: center;
            gap: 0.5rem;
            color: white;
            text-decoration: none;
            padding: 0.5rem 1rem;
            border-radius: 8px;
            transition: background-color 0.3s ease;
        }

        .back-button:hover {
            background-color: rgba(255, 255, 255, 0.15);
            color: white;
        }

        /* 添加视频播放器主题定制 */
        .video-js.vjs-theme-forest {
            --vjs-theme-forest--primary: #4361ee;
            --vjs-theme-forest--secondary: #4895ef;
        }
    </style>
</head>
<body>
    <header class="header">
        <div class="main-container">
            <a href="/" class="back-button">
                <i class="fas fa-arrow-left"></i>
                返回首页
            </a>
        </div>
    </header>

    <main class="main-container">
        <div class="video-section">
            <div class="video-player-container">
                <video
                    id="videoPlayer"
                    class="video-js vjs-theme-forest vjs-big-play-centered"
                    controls
                    preload="auto"
                    width="100%"
                    poster="/images/thumbnails/default.jpg"
                    data-setup="{}"
                >
                    <p class="vjs-no-js">
                        要观看此视频，请启用 JavaScript，并考虑升级到支持 HTML5 视频的浏览器
                    </p>
                </video>
                <div class="video-info">
                    <h1 class="video-title" id="videoTitle"></h1>
                    <div class="video-meta">
                        <span><i class="fas fa-folder"></i> <span id="videoCategory"></span></span>
                        <span><i class="fas fa-calendar"></i> <span id="videoUploadTime"></span></span>
                        <span><i class="fas fa-eye"></i> <span id="videoViews"></span> 次观看</span>
                    </div>
                    <div class="video-description" id="videoDescription"></div>
                </div>
            </div>

            <div class="related-videos">
                <h3>相关视频</h3>
                <div id="relatedVideosList"></div>
            </div>
        </div>
    </main>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    <script src="https://vjs.zencdn.net/8.3.0/video.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
    <script>
        let player = null;
        let currentVideoId = null;

        // 获取URL参数
        function getUrlParam(param) {
            const urlParams = new URLSearchParams(window.location.search);
            return urlParams.get(param);
        }

        // 格式化日期
        function formatDate(dateString) {
            const date = new Date(dateString);
            return date.toLocaleDateString('zh-CN', {
                year: 'numeric',
                month: '2-digit',
                day: '2-digit',
                hour: '2-digit',
                minute: '2-digit'
            });
        }

        // 加载视频信息
        function loadVideoInfo(videoId) {
            currentVideoId = videoId;
            
            fetch(`/api/videos/${videoId}`)
                .then(response => response.json())
                .then(video => {
                    // 更新页面标题
                    document.title = `${video.title} - 视频播放平台`;
                    
                    // 更新视频信息
                    document.getElementById('videoTitle').textContent = video.title;
                    document.getElementById('videoCategory').textContent = video.category;
                    document.getElementById('videoUploadTime').textContent = formatDate(video.uploadTime);
                    document.getElementById('videoViews').textContent = video.views || 0;
                    document.getElementById('videoDescription').textContent = video.description || '暂无描述';

                    // 加载视频流
                    fetch(`/api/videos/hls/${video.fileName}`)
                        .then(response => response.text())
                        .then(hlsUrl => {
                            player.src({
                                src: hlsUrl,
                                type: 'application/x-mpegURL'
                            });
                        });

                    // 加载相关视频
                    loadRelatedVideos(video.category);
                });
        }

        // 加载相关视频
        function loadRelatedVideos(category) {
            fetch(`/api/videos/list/${category}?page=0&size=6`)
                .then(response => response.json())
                .then(videos => {
                    const container = document.getElementById('relatedVideosList');
                    container.innerHTML = '';
                    
                    videos
                        .filter(video => video.id != currentVideoId)
                        .forEach(video => {
                            const item = document.createElement('div');
                            item.className = 'related-video-item';
                            item.onclick = () => window.location.href = `/play.html?id=${video.id}`;
                            
                            item.innerHTML = `
                                <img src="${video.thumbnailUrl}" class="related-video-thumb" alt="${video.title}">
                                <div class="related-video-info">
                                    <div class="related-video-title">${video.title}</div>
                                    <div class="related-video-meta">
                                        <span><i class="fas fa-eye"></i> ${video.views || 0} 次观看</span>
                                    </div>
                                </div>
                            `;
                            
                            container.appendChild(item);
                        });
                });
        }

        // 页面加载完成后执行
        document.addEventListener('DOMContentLoaded', function() {
            // 初始化视频播放器
            player = videojs('videoPlayer', {
                controls: true,
                fluid: true,
                html5: {
                    vhs: {
                        overrideNative: true
                    }
                }
            });

            // 加载视频
            const videoId = getUrlParam('id');
            if (videoId) {
                loadVideoInfo(videoId);
            }
        });

        // 页面卸载时清理
        window.addEventListener('beforeunload', function() {
            if (player) {
                player.dispose();
                player = null;
            }
        });
    </script>
</body>
</html> 